<?php
require_once('../../classes/User.php');


session_start();

$user = new User;
$email = $_POST['email'];
$pass = $_POST['password'];
$userAccount = $user->loginUser($email,$pass);

if(isset($_POST['log_in']))
{
    if($userAccount==null){
        header('Location: ../../index.php?action=loginerror=1');   
    }
    else{
        $_SESSION['login'] = 1;
        $find = mysql_query("SELECT account_id FROM account WHERE email = '$email'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $id = $row['account_id'];
            }
        $find = mysql_query("SELECT userinfo.user_id FROM account,userinfo  WHERE account.account_id = '$id'  AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['user_id'] = $row['user_id'];
            }
        $find = mysql_query("SELECT fname FROM account,userinfo  WHERE account.account_id = '$id'  AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['fname'] = $row['fname'];
            }
        $find = mysql_query("SELECT lname FROM account,userinfo  WHERE account.account_id = '$id' AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['lname'] = $row['lname'];
            }
        $find = mysql_query("SELECT email FROM account,userinfo  WHERE account.account_id = '$id' AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['email'] = $row['email'];
            }
        $find = mysql_query("SELECT password FROM account,userinfo  WHERE account.account_id = '$id' AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['password'] = $row['password'];
            }
        $find = mysql_query("SELECT gender FROM account,userinfo  WHERE account.account_id = '$id' AND userinfo.account_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['gender'] = $row['gender'];
            }
        echo $_SESSION['fname'].$_SESSION['lname'].$_SESSION['email'].$_SESSION['password'].$_SESSION['gender'].$_SESSION['user_id'];
        header("Location: ../../index.php");
    }
}
?>